package com.example.proxy;

import com.example.proxy.interfaces.MInterface;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Main {
    public static void main(String[] args) {
        MInterface mInterface = new MPrint();
        MInterface mPrint = (MInterface) Proxy.newProxyInstance(mInterface.getClass().getClassLoader(), mInterface.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                System.out.println("被我代理了");
                System.out.println(method.getName());
                method.invoke(mInterface, objects);
                System.out.println(method.getName());
                return null;
            }
        });
        mPrint.print();
    }
}
